﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Diagnostics;
using CustomControls;

namespace Buccaneer
{
    class BitmapButtonsInitializer
    {
        public static void setFlatAppearance(ref BitmapButton bitmapButton)
        {
            bitmapButton.TabStop = true;
        }

        public static Image resizeImage(Image imgToResize, Size size)
        {
            return imgToResize.GetThumbnailImage(size.Width, size.Height, null, IntPtr.Zero);
        }

        public static void loadImage(ref BitmapButton bitmapButton, string imageName)
        {
            try
            {
                Options.WriteComment(" -  loading image " + imageName + "...");
                bitmapButton.Image = new Bitmap(Directory.GetCurrentDirectory() + @"\Layout\" + imageName + ".png");
                Options.WriteComment("(i) Succeeded.");
            }
            catch (Exception ex)
            {
                Debug.Write("(X) An error occurred:" + ex.Message + "\nsource:" + ex.Source);
                MessageBox.Show("Error in loading the following image: " + Directory.GetCurrentDirectory() + @"\Layout\" + imageName + ".png\n\nException info: " + ex.Message);
                bitmapButton.Image = null;
                Thread.CurrentThread.Abort();
                return;
            }
            bitmapButton.LoadImages(imageName);
        }

        #region Navigation

        public static BitmapButton AddNavigateBack()
        {
            BitmapButton bitmapButton = new BitmapButton();
            bitmapButton.Location = new Point(0, 0);
            bitmapButton.TabIndex = 0;
            bitmapButton.Text = "";
            loadImage(ref bitmapButton, "navBack");
            bitmapButton.Size = bitmapButton.Image.Size;
            //bitmapButton.Disable();
            setFlatAppearance(ref bitmapButton);
            return bitmapButton;
        }

        public static BitmapButton AddNavigateUp()
        {
            BitmapButton bitmapButton = new BitmapButton();
            bitmapButton.Location = new Point(48, 0);
            bitmapButton.TabIndex = 0;
            bitmapButton.Text = "";
            loadImage(ref bitmapButton, "navUp");
            bitmapButton.Size = bitmapButton.Image.Size;
            //bitmapButton.Disable();
            setFlatAppearance(ref bitmapButton);
            return bitmapButton;
        }

        public static BitmapButton AddNavigateDown()
        {
            BitmapButton bitmapButton = new BitmapButton();
            bitmapButton.Location = new Point(48, 51);
            loadImage(ref bitmapButton, "navDown");
            bitmapButton.Size = bitmapButton.Image.Size;
            bitmapButton.TabIndex = 0;
            bitmapButton.Text = "";
            //bitmapButton.Disable();
            setFlatAppearance(ref bitmapButton);
            return bitmapButton;
        }

        public static BitmapButton AddNavigateForward()
        {
            BitmapButton bitmapButton = new BitmapButton();
            bitmapButton.Location = new Point(89, 0);
            bitmapButton.TabIndex = 0;
            bitmapButton.Text = "";
            loadImage(ref bitmapButton, "navForward");
            bitmapButton.Size = bitmapButton.Image.Size;
            //bitmapButton.Disable();
            setFlatAppearance(ref bitmapButton);
            return bitmapButton;
        }

        #endregion

        #region Control

        public static BitmapButton AddControlGo()
        {
            BitmapButton bitmapButton = new BitmapButton();
            bitmapButton.Location = new Point(0, 0);
            bitmapButton.TabIndex = 0;
            bitmapButton.Text = "";
            loadImage(ref bitmapButton, "ctrlGo");
            bitmapButton.Size = bitmapButton.Image.Size;
            setFlatAppearance(ref bitmapButton);
            return bitmapButton;
        }


        public static BitmapButton AddControlClose()
        {
            BitmapButton bitmapButton = new BitmapButton();
            bitmapButton.Location = new Point(51, 0);
            bitmapButton.TabIndex = 0;
            bitmapButton.Text = "";
            loadImage(ref bitmapButton, "ctrlClose");
            bitmapButton.Size = bitmapButton.Image.Size;
            setFlatAppearance(ref bitmapButton);
            return bitmapButton;
        }

        #endregion


    }
}
